<script src="__PUBLIC__/ganged/Js/city-picker.data.js"></script>
<script src="__PUBLIC__/ganged/Js/city-picker.js"></script>
<script src="__PUBLIC__/ganged/Js/main.js"></script>
<!-- css -->
<link href="__PUBLIC__/ganged/Css/city-picker.css" rel="stylesheet" type="text/css" />

<script type="text/javascript" charset="utf-8" src="__PUBLIC__/admin/js/uploadify/jquery.uploadify.min.js" ></script>
<link rel="stylesheet" charset="utf-8" type="text/css" href="__PUBLIC__/admin/js/uploadify/uploadify.css"> 
<script type="text/javascript" charset="utf-8" src="__PUBLIC__/admin/js/upload.js" ></script>
<script type="text/javascript" src="http://api.map.baidu.com/api?v=2.0&ak=yWnFso0oyjmX79HzCx1DRz2sBtvweQfI"></script>
<div class="container" style="padding-top: 50px;">
    <div class="row clearfix">
        <div class="col-md-12 column">
            <form class="form-horizontal" role="form" id="post_form" action="{:U('')}">
                <div class="form-group">
                    <label for="title" class="col-sm-2 control-label">昵称:</label>
                    <div class="col-sm-9">
                        <p class="form-control-static">{$info['nickname']|default=''}</p>
                    </div>
                </div>
                <div class="form-group">
                    <label for="title" class="col-sm-2 control-label">手机号:</label>
                    <div class="col-sm-9">
                        <p class="form-control-static">{$info['phone']|default=''}</p>
                    </div>
                </div>    
                <div class="form-group">
                    <label for="nearby_imgs" class="col-sm-2 control-label">图片:<span style="color: red;">*</span></label>
                    <div class="col-sm-10 js_upload_imgs">
                        <input type="file" class="form-control" id="nearby_imgs"><br /> 
                        <div name="nearby_imgs" class="upviewer">
                            <ul>
                                <notempty name="info['nearby_imgs']">
                                    <php>
                                        $info['nearby_imgs'] = explode(',', $info['nearby_imgs']) ;
                                    </php>
                                    <volist name="info['nearby_imgs']" id="img">
                                        <li>
                                            <img src="{$img}"/><a d_path="{$img}">删除</a>
                                        </li>
                                    </volist>
                                </notempty>
                            </ul>
                        </div>
                    </div>
                </div>
                <div class="form-group">
                    <label for="nearby_video" class="col-sm-2 control-label">视频(mp4格式):</label>
                    <div class="col-sm-10 js_upload_video">
                        <input type="file" class="form-control" id="nearby_video"  value="{$info.nearby_video}"><br /> 
                        <div name="nearby_video" class="upviewer">
                            <ul>
                                <notempty name="info['nearby_video']">
                                    <li style="height:300px;width: auto;">
                                        <video style="height:280px;" controls src="{$info.nearby_video}"></video><a d_path="{$info.nearby_video}">删除</a>
                                    </li>
                                </notempty>
                            </ul>
                        </div>
                    </div>
                </div>
                <div class="form-group">
                    <label for="sign_name" class="col-sm-2 control-label">个签:</label>
                    <div class="col-sm-5">
                        <input type="text" class="form-control" name="sign_name" value="{$info.sign_name}"/>
                    </div>
                </div>
                <div class="form-group">
                    <label for="height" class="col-sm-2 control-label">身高:</label>
                    <div class="col-sm-5">
                        <input type="text" class="form-control" name="height" value="{$info.height}"/>
                    </div>
                </div>
                <div class="form-group">
                    <label for="weight" class="col-sm-2 control-label">体重:</label>
                    <div class="col-sm-5">
                        <input type="text" class="form-control" name="weight" value="{$info.weight}"/>
                    </div>
                </div>
                <div class="form-group">
                    <label for="hobby" class="col-sm-2 control-label">爱好:</label>
                    <div class="col-sm-5">
                        <input type="text" class="form-control" name="hobby" value="{$info.hobby}"/>
                    </div>
                </div>
                <div class="form-group">
                    <label for="nearby_age" class="col-sm-2 control-label">年龄:</label>
                    <div class="col-sm-5">
                        <input type="text" class="form-control" name="nearby_age" value="{$info.nearby_age}"/>
                    </div>
                </div>
                <div class="form-group">
                    <label for="ds" class="col-sm-2 control-label">城市:<span style="color: red;">*</span></label>
                    <div id="distpicker" style="margin-left:20%">
                        <div class="form-group">
                            <div style="position: relative;">
                                <input class="form-control" name="city" readonly type="text" value="{$info['city']|default=''}" data-toggle="city-picker" style="width:400px;">
                            </div>
                        </div>
                        <div class="form-group">
                            <button class="btn btn-warning" id="reset" type="button">重置</button>
                            <button class="btn btn-danger" id="destroy" type="button">确定</button>
                        </div>
                    </div>
                </div>
                <div class="form-group">
                    <label for="nearby_address" class="col-sm-2 control-label">地址:<span style="color: red;">*</span></label>
                    <div class="col-sm-5">
                        <input type="text" class="form-control" name="nearby_address" value="{$info.nearby_address}"/>
                    </div>
                </div>
                <div class="form-group">
                    <label for="constellation" class="col-sm-2 control-label">星座:</label>
                    <div class="col-sm-5">
                        <input type="text" class="form-control" name="constellation" value="{$info.constellation}"/>
                    </div>
                </div>
                <div class="form-group">
                    <label for="skill" class="col-sm-2 control-label">技能:</label>
                    <div class="col-sm-5">
                        <input type="text" class="form-control" name="skill" value="{$info.skill}"/>
                    </div>
                </div>
                <div class="form-group">
                    <div class="col-sm-offset-2 col-sm-10">
                        <input type="hidden" name="nearby_lat" id="nearby_lat" value="0" />
                        <input type="hidden" name="nearby_lng" id="nearby_lng" value="0" />
                        <input type="hidden" name="id" value="{$info.id}">
                        <button type="button" class="btn btn-primary" id="btn" lng="0" lat="0">提交</button>
                    </div>
                </div>
            </form>
        </div>
    </div>
</div>
<script>
    function getPlace(addr) {
        var myGeo = new BMap.Geocoder();
        myGeo.getPoint(addr, function(point) {
            if(point) {
                $("#nearby_lat").val(point.lat);
                $("#nearby_lng").val( point.lng);
            } else {
                $("#nearby_lat").val(0);
                $("#nearby_lng").val(0);
            }
        });
    }
    $(function () {
        $("#btn").click(function () {
            var $form = $("#post_form");
            var $data = {};
            var $form_data = $form.serializeArray();
            $.each($form_data, function (k, v) {
                $data[v.name] = v.value;
            });
            if(!$data.nearby_imgs){
                alert("请上传图片");
                return false;
            }
            if(!$data.city){
                alert("请选择城市");
                return false;
            }
            if(!$data.nearby_address){
                alert("请输入地址");
                return false;
            }

            getPlace($data.city+$data.nearby_address);
            if($data.nearby_lat == 0 || $data.nearby_lng==0){
                alert("正在定位,请在3秒之后添加");
                return false;
            }
            $.post($form.attr('action'), $data, function (obj) {
                alert(obj.m);
                if (obj.s) {
                    if (typeof (obj.url) != "undefined" && obj.url) {
                        location.href = obj.url;
                    }
                }
            });
            return false;
        });
    });
</script>